package com.springBoot.springBootSysCore.modules.controller.web.system;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.springBoot.springBootSysCore.modules.controller.web.base.BaseController;
import com.springBoot.springBootSysCore.modules.entity.system.SysLog;
import com.springBoot.springBootSysCore.modules.services.system.SysLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *系统编码
 */
@Controller
@RequestMapping("${adminPath}/sysLog")
public class SysLogController extends BaseController<SysLog,String> {
    @Autowired
    private SysLogService sysLogService;

    @ModelAttribute("entity")
    public SysLog get(@RequestParam(required = false) String id) {
        if (StringUtils.isNotBlank(id)) {
            return sysLogService.findById(id);
        } else {
            return new SysLog();
        }
    }
    /**
     * 分页查询
     * @param request
     * @param model
     * @return
     * @throws JsonProcessingException
     */
    @RequestMapping("queryByPage")
    @ResponseBody
    public Object queryByPage(HttpServletRequest request,
                              Model model) throws JsonProcessingException{
        Map<String, Object> map = new HashMap<String, Object>();
        return super.queryByPageForDataTables( model, request,map, "createDate", "desc");
    }

    @RequestMapping(value="findOne",method= RequestMethod.GET)
    public String findOne(String id,Model model){
        return "system/log/logChange";
    }

}
